﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing ;
using DotSpatial .Drawing ;
using DotSpatial.Geometries;

using DotSpatial.Map;
using DotSpatial.Data;

using System.Drawing.Design ;
using System.Windows.Forms ;
using System.Windows.Forms.Design ;

using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.IO ;
using System.Data;



namespace HuanGis
{


    public class PointSymbolEditor : UITypeEditor
    {

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService DialogProvider;
            DialogProvider = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (DialogProvider != null)
            {

                DotSpatial.Forms.DetailedPointSymbolDialog MyPointSymbolDlg = new DotSpatial.Forms.DetailedPointSymbolDialog((PointSymbolizer)value);

                //MyPointSymbolDlg.Symbolizer = (DotSpatial.Drawing.IPointSymbolizer)value;

                if (DialogProvider.ShowDialog(MyPointSymbolDlg) == DialogResult.OK)

                    return MyPointSymbolDlg.Symbolizer;
                else
                    return value;
            }
            else
                return value;

        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {

            return UITypeEditorEditStyle.Modal;

            //return base.GetEditStyle(context);
        }
        
    }



    public class FEPointLayer : FEditableLayer
    {

        public FEPointLayer(string id ):base(id)
        {
            this.m_Type = FeatureTypes.Point;
                    
            
        }

        //点的常用属性，点的样式等。作为资源嵌入的也可以计算在内

        #region "属性封装"
               
       
        //刘加

        private object _PointSymbol = new PointSymbolizer();

        [Editor(typeof(PointSymbolEditor), typeof(UITypeEditor))]  
        [Category("基体信息"), DisplayName("点基本信息设置")]
        public object PointSymbol
        {
            get { return this._PointSymbol; }
            set
            {
                this._PointSymbol = value;
                this.OnSetSymbol();

            }
        }

        protected void OnSetSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).Symbolizer = (PointSymbolizer)_PointSymbol;
        }

        private object _SelectSymbol = new PointSymbolizer();

        [Editor(typeof(PointSymbolEditor), typeof(UITypeEditor))]  
        [Category("基体信息"), DisplayName("所选点基本信息设置")]
        public object SelectionSymbol
        {
            get { return this._SelectSymbol; }
            set
            {
                this._SelectSymbol = value;
                this.OnSetSelectSymbol();

            }
        }

        protected void OnSetSelectSymbol()
        {
            if (this.BRunning)
                (this.ILayer as IFeatureLayer).SelectionSymbolizer = (PointSymbolizer)this._SelectSymbol;        
        }



        //现在又一个疑问，是调用系统默认的属性对话框呢，还是自己写，包括树，以及属性编辑。


        #endregion



        # region protected methods

       


        # endregion


        public override void AddShape(FShape shp)
        {
            if (shp.normalPts == null || shp.normalPts.Count == 0) return;

            base.AddShape(shp);
             
            (this.ILayer.DataSet as IFeatureSet).Features.Add(shp.normalPts[0]);

        }

        public override void AddShapeRane(List<FShape> shps)
        {
            base.AddShapeRane(shps);

            for (int i = 0; i < shps.Count; i++)
            {
                this.AddShape(shps[i]);
            }
        }



    }
}
